home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_540 / parm / parm_src.lzh / LibSup.c < prev    next >
C/C++ Source or Header  |  1991-07-20  |  5KB  |  207 lines

  1. /*
  2.  *    LibSup.c - Copyright © 1990 by S.R. & P.C.
  3.  *
  4.  *    Created:    22 Sep 1990  20:52:16
  5.  *    Modified:    20 Jul 1991  11:47:47
  6.  *
  7.  *    Make>> make
  8.  */
  9.  
  10. #include "ParMBase.h"
  11.  
  12.  
  13. #define PARMREVISION    7        /* would be nice to auto-increment this */
  14.  
  15. char ParMLibName[] = "parm.library";
  16. char ParMLibId[]   = "V1.7 (20 Jul 1991)\r\n";
  17.  
  18. void InstallHandler(void);
  19. void RemoveHandler(void);
  20.  
  21. void ParMLibInit(void);
  22. long ParMLibOpen(void);
  23. long ParMLibClose(void);
  24. long ParMLibExpunge(void);
  25.  
  26. #pragma amicall(ParMBase, 0x06, ParMLibOpen())
  27. #pragma amicall(ParMBase, 0x0c, ParMLibClose())
  28. #pragma amicall(ParMBase, 0x12, ParMLibExpunge())
  29.  
  30. long DosWrite(BPTR file, char *buffer, long length);
  31. #pragma amicall(DOSBase, 0x30, DosWrite(d1,d2,d3))
  32.  
  33.  
  34. extern struct ExecBase *SysBase;
  35. extern struct Library  *DOSBase;
  36. extern struct Resident ParMLibRomTag;
  37.  
  38. struct ParMBase *ParMBase;        /* Have a global ParMBase for internal functions */
  39. struct ArpBase  *ArpBase;
  40. struct ReqLib   *ReqBase;
  41. struct IconBase *IconBase;
  42. struct LayersBase *LayersBase;
  43. struct IntuitionBase *IntuitionBase;
  44.  
  45.  
  46. /* library initialization table, used for AUTOINIT libraries */
  47.  
  48. struct InitTable {
  49.     ULONG it_DataSize;            /* library data space size            */
  50.     void  **it_FuncTable;        /* table of entry points            */
  51.     void  *it_DataInit;            /* table of data initializers        */
  52.     void  (*it_InitFunc)(void);    /* initialization function to run    */
  53. };
  54.  
  55.  
  56. void *libfunctab[] = {    /* my function table */
  57.     ParMLibOpen,                /* standard open    */
  58.     ParMLibClose,                /* standard close    */
  59.     ParMLibExpunge,                /* standard expunge    */
  60.     0,
  61.  
  62.     /* real lib functions */
  63.  
  64.     ParseMenus,
  65.     FreeMenus,
  66.     ARun,
  67.     Run,
  68.     WBRun,
  69.     GetTool,
  70.     MakeWBArg,
  71.     MakeWBStartup,
  72.     WBFree,
  73.     Command,
  74.     ParseLine,
  75.     DosError,
  76.     StrIoErr,
  77.     MakeMenuShortCut,
  78.     InitDefaults,
  79.     FreeRepliedWBMessages,
  80.     NewMinList,
  81.     CopyStr,
  82.     FreeStr,
  83.     IsHidden,
  84.     GetWindow,
  85.     CreateExtIO,
  86.     CleanUp,
  87.     (void *)-1L                /* end of function vector table */
  88. };
  89.  
  90.  
  91. struct InitTable ParMLibInitTab =  {
  92.     sizeof(struct ParMBase),
  93.     libfunctab,
  94.     0,                        /* will initialize my data in funkymain()    */
  95.     ParMLibInit
  96. };
  97.  
  98.  
  99. /* Init the global ParMBase */
  100.  
  101. void StoreParMBase(struct ParMBase *pb)
  102. {
  103.     ParMBase = pb;
  104. }
  105.  
  106.  
  107. void _main(struct ParMBase *ParMBase, unsigned long seglist)
  108. {
  109.     ParMBase->pb_SegList = seglist;
  110.  
  111.     /* -----  init. library structure  ----- */
  112.     ParMBase->pb_Lib.lib_Node.ln_Type = NT_LIBRARY;
  113.     ParMBase->pb_Lib.lib_Node.ln_Name = (char *)ParMLibName;
  114.     ParMBase->pb_Lib.lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
  115.     ParMBase->pb_Lib.lib_Version = ParMLibRomTag.rt_Version;
  116.     ParMBase->pb_Lib.lib_Revision = PARMREVISION;
  117.     ParMBase->pb_Lib.lib_IdString = (APTR)ParMLibId;
  118.     ParMBase->pb_MsgPort.mp_Flags = PA_IGNORE;
  119.     NewMinList((struct MinList *)&ParMBase->pb_MsgPort.mp_MsgList);
  120.     StoreParMBase(ParMBase);
  121. }
  122.  
  123.  
  124. long ParMLibOpen(void)
  125. {
  126.     struct ParMBase *ParMBase;
  127.     struct Process *pp;
  128.  
  129.     pp = (struct Process *)SysBase->ThisTask;
  130.     if (!ReqBase && !(ReqBase = (struct ReqLib *)OpenLibrary("req.library",1))) {
  131.         if (pp->pr_COS)
  132.             DosWrite(pp->pr_COS, "You need req.library\n", 21L);
  133.         return NULL;
  134.     }
  135.     if (!IconBase && !(IconBase = (struct IconBase *)OpenLibrary("icon.library", 0L))) {
  136.         SimpleRequest("parm.library", "You need icon.library!");
  137.         return NULL;
  138.     }
  139.     if (!LayersBase && !(LayersBase = (struct LayersBase *)OpenLibrary("layers.library", 0L)))
  140.         return NULL;
  141.     /* Each user must open arp.library for individual tracked resources */
  142.     if (!(ArpBase = (struct ArpBase *)OpenLibrary("arp.library", 39))) {
  143.         SimpleRequest("parm.library", "You need arp.library V39+\n");
  144.         return NULL;
  145.     }
  146.     ParMBase->ArpBase = ArpBase;
  147.     ParMBase->ReqBase = ReqBase;
  148.     ParMBase->IconBase = IconBase;
  149.     ParMBase->LayersBase = LayersBase;
  150.     IntuitionBase = (struct IntuitionBase *)ArpBase->IntuiBase;
  151.     /* Handler is removed each time OpenCnt becomes zero */
  152.     if (ParMBase->pb_Lib.lib_OpenCnt == 0)
  153.         InstallHandler();
  154.     /* mark us as having another customer */
  155.     ParMBase->pb_Lib.lib_OpenCnt++;
  156.     /* prevent delayed expunges (standard procedure) */
  157.     ParMBase->pb_Lib.lib_Flags &= ~LIBF_DELEXP;
  158.     return (long)ParMBase;
  159. }
  160.  
  161.  
  162. long ParMLibClose(void)
  163. {
  164.     struct ParMBase *ParMBase;
  165.  
  166.     CloseLibrary(ArpBase);
  167.     if (--ParMBase->pb_Lib.lib_OpenCnt == 0 && ParMBase->pb_MsgCnt == 0) {
  168.         RemoveHandler();
  169.         if  (ParMBase->pb_Lib.lib_Flags & LIBF_DELEXP) {
  170.             /* no more people have me open, and I have a delayed expunge pending */
  171.             return ParMLibExpunge(); /* return segment list    */
  172.         }
  173.     }
  174.     return NULL;
  175. }
  176.  
  177.  
  178. long ParMLibExpunge(void)
  179. {
  180.     struct ParMBase *ParMBase;
  181.     ULONG seglist = 0;
  182.     long libsize;
  183.     extern struct Library *DOSBase;
  184.  
  185.     if (ParMBase->pb_Lib.lib_OpenCnt == 0 && ParMBase->pb_MsgCnt == 0) {
  186.         if (ReqBase)
  187.             CloseLibrary(ReqBase);
  188.         if (IconBase)
  189.             CloseLibrary(IconBase);
  190.         if (LayersBase)
  191.             CloseLibrary(LayersBase);
  192.         /* really expunge: remove libbase and freemem */
  193.         seglist    = ParMBase->pb_SegList;
  194.         Remove(&ParMBase->pb_Lib.lib_Node); /* i'm no longer an installed library */
  195.         libsize = ParMBase->pb_Lib.lib_NegSize+ParMBase->pb_Lib.lib_PosSize;
  196.         FreeMem((char *)ParMBase-ParMBase->pb_Lib.lib_NegSize, libsize);
  197.         CloseLibrary(DOSBase);
  198.     }
  199.     else
  200.         ParMBase->pb_Lib.lib_Flags |= LIBF_DELEXP;
  201.  
  202.     /* return NULL or real seglist */
  203.     return (long)seglist;
  204. }
  205.  
  206.  
  207.